//
//  LZSOptionViewController.m
//  IOSProject
//
//  Created by lzs on 2018/4/18.
//  Copyright © 2018年 com.linzhisheng. All rights reserved.
//

#import "LZSOptionViewController.h"
#import "LSTextView.h"

@interface LZSOptionViewController ()<UITextViewDelegate>

@property (nonatomic, strong)   LSTextView*textView;
@end

@implementation LZSOptionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.edgesForExtendedLayout = 0;
    self.view.backgroundColor = [UIColor colorWithHexString:@"0xececec"];
    self.navigationItem.title = @"意见反馈";
    UIView *topView = [[UIView alloc] init];
    topView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:topView];
    
    LSTextView *textView= [[LSTextView alloc] init];
    self.textView  = textView;
    textView.keyboardType = UIKeyboardTypeDefault;
    textView.returnKeyType = UIReturnKeyDefault;
    // 设置文本字体
    textView.font = [UIFont fontWithName:@"Arial" size:16.5f];
    // 设置文本颜色
    textView.textColor = [UIColor colorWithRed:51/255.0f green:51/255.0f blue:51/255.0f alpha:1.0f];
    // 设置文本对齐方式
    textView.textAlignment = NSTextAlignmentLeft;
    // 设置自动纠错方式
    textView.autocorrectionType = UITextAutocorrectionTypeNo;
    // 设置文本框背景颜色
    textView.backgroundColor = [UIColor colorWithHexString:@"0xececec"];
    textView.textContainerInset = UIEdgeInsetsMake(5, 5, 5, 5);
    // 设置是否可以拖动
    textView.scrollEnabled = YES;
    
    textView.placeholderColor = [UIColor lightGrayColor];
    textView.placeholder = @"请详细描述您的意见和遇到的问题~";
    textView.font = [UIFont systemFontOfSize:17];
    textView.delegate = self;
    [textView.layer setCornerRadius:10.0f];
    [self.view addSubview:textView];
    //自适应高度
    textView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
    [topView addSubview:textView];
    
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.view);
        make.bottom.equalTo(textView.mas_bottom).mas_offset(15);
    }];
    
    
    [textView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(topView.mas_top).mas_offset(15);
        make.left.equalTo(topView.mas_left).mas_offset(15);
        make.right.equalTo(topView.mas_right).mas_offset(-15);
        make.height.mas_equalTo(150);
    }];
    
    UIButton *saveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [saveBtn setTitle:@"发送反馈意见" forState:UIControlStateNormal];
    [saveBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    saveBtn.backgroundColor = [UIColor redColor];
    saveBtn.titleLabel.font = [UIFont systemFontOfSize:20];
    saveBtn.layer.cornerRadius = 25;
    saveBtn.layer.masksToBounds = YES;
    [saveBtn addTarget:self action:@selector(savePersonIntroduceAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:saveBtn];
    [saveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view.mas_centerX);
        make.top.equalTo(topView.mas_bottom).mas_offset(30);
        make.size.mas_equalTo(CGSizeMake(self.view.frame.size.width-40, 60));
    }];
    
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.colors = @[(__bridge id)[UIColor colorWithHexString:@"0xff8065"].CGColor, (__bridge id)[UIColor colorWithHexString:@"0xf26c69"].CGColor, (__bridge id)[UIColor colorWithHexString:@"0xff5e70"].CGColor];
    gradientLayer.locations = @[@0.3, @0.5, @1.0];
    gradientLayer.startPoint = CGPointMake(0, 0);
    gradientLayer.endPoint = CGPointMake(1.0, 0);
    
    gradientLayer.frame = CGRectMake(0, 0, self.view.frame.size.width-40, 60);//CGRectMake(0, 0, CGRectGetWidth(_loginBtn.frame), CGRectGetHeight(_loginBtn.frame));
    
    [saveBtn.layer addSublayer:gradientLayer];
    [saveBtn bringSubviewToFront:saveBtn.titleLabel];
    
}

- (void)textViewDidChange:(LSTextView *)textView

{
    
    if([textView.placeholder length] == 0)
    {
        return;
    }
    if([textView.placeholder length]  == 0)
    {
        [textView.placeHolderLabel setAlpha:1];
    }
    else
    {
        [textView.placeHolderLabel  setAlpha:0];
    }
    
    if ([textView.text isEqualToString:@""]) {
        [textView.placeHolderLabel setAlpha:1];
    }
}

-(void)savePersonIntroduceAction:(UIButton *)btn{
    
//    if (!self.access_token) {
//        [self showTostMessage:@"您还未登录，请先登录.."];
//        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//            LSLoginVC *loginvc = [[LSLoginVC alloc] init];
//            [self.navigationController pushViewController:loginvc animated:YES];
//        });
//
//        return;
//    }
//
    //判断是否为空
    if (self.textView.text.length==0) {
        [self showTostMessage:@"反馈意见不能为空~"];
        return;
    }
    
    
//
//    [[LSPersonHttpsManager shareManager] PostUserAddFeedBackWithContent:self.textView.text withAccessToken:self.access_token withSuccess:^(id responseObject) {
//        NSLog(@"responseObject%@",responseObject);
        [self showTostMessage:@"感谢您提的宝贵意见。。"];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.navigationController popViewControllerAnimated:YES];
    });
    
//        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//            [self.navigationController popViewControllerAnimated:YES];
//        });
//
//    } WithFailure:^(NSError *error) {
//        [self showTostMessage:error.domain];
//    }];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
